package com.eqdd.yiqidian.utils;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.BaseApplication;
import com.melink.bqmmsdk.sdk.BQMM;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import io.rong.imkit.utils.RongDateUtils;

/**
 * Created by lv on 17-8-9.
 */

public class DateUtil {

    private static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    private static SimpleDateFormat sf1 = new SimpleDateFormat("yyyy/M/d HH:mm:ss");

    public static String format(String content, String format) {
        if (content == null) {
            return "";
        }
        Date date = null;
        try {
            date = sf.parse(content);
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("DateUtil 日期格式錯誤");
            return "";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.format(date);
    }

    public static String format(String content) {
        if (content == null) {
            return "";
        }
        Date date = null;
        try {
            date = sf.parse(content);
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("DateUtil 日期格式錯誤");
            return "";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return simpleDateFormat.format(date);
    }

    public static String formatYMD(String content) {
        if (content == null) {
            return "";
        }
        content = content.replace("/", "-").replace("T", " ");
        return content.substring(0, !content.contains(" ") ? content.length() : content.indexOf(" "));
    }


    public static String format1(String content) {
        if (content == null) {
            return "";
        }
        Date date = null;
        try {
            date = sf1.parse(content);
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("DateUtil 日期格式錯誤");
            return "";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return simpleDateFormat.format(date);
    }

    public static String format1(String content, String format) {
        if (content == null) {
            return "";
        }
        Date date = null;
        try {
            date = sf1.parse(content);
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("DateUtil 日期格式錯誤");
            return "";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.format(date);
    }

    public static Date parseNetTime(String time) {

        SimpleDateFormat sf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
        try {
            return sf.parse(time);
        } catch (ParseException e) {
            System.out.println("DateUtil->parseNetTime" + "异常");
            e.printStackTrace();
        }
        return null;
    }

    public static String parseRongTime(String time) {
        try {
            return RongDateUtils.getConversationFormatDate(sf.parse(time).getTime(), BaseApplication.getContext());
        } catch (ParseException e) {
            e.printStackTrace();
            return "日期格式错误";
        }
    }

    public static boolean isWork(Calendar instance, String weeks, String festivals) {
        if (weeks.contains(FestivalUtil.getWeek(instance))) {
            return true;
        }
        return FestivalUtil.getFestival(instance) != null && festivals.contains(FestivalUtil.getFestival(instance));
    }

    public static String getZodiac(String date) {
        SimpleDateFormat sf;
        try {
            sf = new SimpleDateFormat("yyyy-MM-dd");
            Date parse = sf.parse(date);
            Calendar instance = Calendar.getInstance();
            instance.setTime(parse);
            int year = instance.get(Calendar.YEAR);
            int shenxiao = (year + 8) % 12;
            String[] stringArray = BaseApplication.getApplication().getResources().getStringArray(R.array.zodiac);
            return stringArray[shenxiao];
        } catch (Exception e) {
            System.out.println("DateUtil->getSymbolic" + e.toString());
        }
        return "";
    }

    public static String parse(Date date, String format) {
        return new SimpleDateFormat(format).format(date);

    }
}
